package com.github.sbb.sherry.primitives.api;

import com.github.sbb.sherry.primitives.annotation.SherryConverter;
import java.util.Objects;

/**
 * 参数转换器，负责将参数转换成指定的类型
 *
 * @param <T>
 */
public interface Converter<T> {

  default String name() {
    SherryConverter declaredAnnotation = this.getClass()
        .getDeclaredAnnotation(SherryConverter.class);
    Objects.requireNonNull(declaredAnnotation);
    return declaredAnnotation.value();
  }

  T convert(String varName, Facts facts);

  T convert(String varName, Fact fact);
}
